package com.itheima.service;

import com.alibaba.dubbo.config.annotation.Service;
import com.itheima.dao.OrderSettingDao;
import com.itheima.pojo.OrderSetting;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;

@Service(interfaceClass = OrderSettingService.class)
@Transactional
public class OrderSettingServiceImpl implements OrderSettingService {

    @Autowired
    private OrderSettingDao orderSettingDao;

    @Override
    public void editNumber(OrderSetting orderSetting) {
        //判断当前日期是否已设置
        Integer count=orderSettingDao.findCountByOrderDate(orderSetting.getOrderDate());
        //如果已设置，修改预约人数
        if (count>0){
            orderSettingDao.edit(orderSetting);
        }else {
            //如果未设置，添加
            orderSettingDao.add(orderSetting);
        }


    }

    @Override
    public List<OrderSetting> getOrderSettingByMonth(String date) {
        List<OrderSetting> orderSettings=orderSettingDao.getOrderSettingByMonth(date);
       /* List<Map> data=new ArrayList<>();
        for (OrderSetting orderSetting : orderSettings) {
            Map map=new HashMap();
            *//*date: 1, number: 120, reservations:*//*
            map.put("date",orderSetting.getOrderDate().getDate())
        }
        */
        return orderSettings;
    }
}
